package com.shop.zdy.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shop.zdy.bo.Mc;
import com.shop.zdy.dao.factory.DAOFactory;
import com.shop.zdy.pub.PublicStrIsNull;

public class McInfoServlet extends MyServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int mcNid = Integer.parseInt(PublicStrIsNull.isNullStr(request.getParameter("mcNid")));
		String fromPage = PublicStrIsNull.isNullStr(request.getParameter("fromPage"));
		String skey = PublicStrIsNull.isNullStr(request.getParameter("skey"));
		String maxType = PublicStrIsNull.isNullStr(request
				.getParameter("maxType"));
		String minType = PublicStrIsNull.isNullStr(request
				.getParameter("minType"));

		int tymax = -1;
		int tymin = -1;
		try {
			tymax = Integer.parseInt(maxType);
		} catch (Exception e) {
		}
		try {
			tymin = Integer.parseInt(minType);
		} catch (Exception e) {
		}

		int recordSize = DAOFactory.createMcDAO().getCount(skey, -1, -1, tymax, tymin);	
		int pastart= this.pagingHandle(request, recordSize)[0];
		int paend= this.pagingHandle(request, recordSize)[1];
		Mc mc = new Mc();
		mc.setCount(1);
		mc.setMcBean(DAOFactory.createMcDAO().selectMc(mcNid));
		request.setAttribute("mcList", DAOFactory.createMcDAO().selectMc(skey,
				-1, -1, tymax, tymin, pastart, paend));
		request.setAttribute("mcTypeList", DAOFactory.createMcTypeDAO()
				.searchMcType());
		request.setAttribute("skey", skey);
		request.setAttribute("typeMax", tymax);
		request.setAttribute("typeMin", tymin);
		request.setAttribute("mc",mc);
		request.getRequestDispatcher(fromPage).forward(request, response);
	}
}
